<?php
declare (strict_types = 1);
namespace app\validate;

use think\Validate;

class Install extends Validate
{
    // 验证 IP或 localhost
    protected $regex = ['host' => "^(((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}|localhost)$"];

    /**
     * 定义验证规则
     */
    protected $rule = [
        'host'          => 'require|regx:host',
        'dbuser'        => 'require|alphaDash',
        'dbname'        => 'require|alphaDash',
        'port'          => 'require|number',
        'prefix'        => 'require|alphaDash',
        'username'      => 'require|max:30',
        'password'      => 'require|max:18|min:6',
    ];

    /**
     * 定义错误信息
     */
    protected $message = [
        'host.require'              => '请输入数据库地址',
        'host.regx'                 => '数据库地址有误',
        'dbuser.require'            => '请输入数据库账号',
        'dbuser.alphaDash'          => '数据库账号格式错误',
        'dbname.require'            => '请输入数据库名称',
        'dbname.alphaDash'          => '数据库名称格式错误',
        'port.require'              => '请输入数据库端口',
        'port.number'               => '数据库端口错误',
        'prefix.require'            => '请输入数据表前缀',
        'prefix.alphaDash'          => '数据表前缀格式错误',
        'username.require'          => '请输入管理员账号',
        'username.max'              => '管理员账号不能超过30位字符',
        'password.require'          => '请输入管理员密码',
        'password.max'              => '管理员密码不能超过18位字符',
        'password.min'              => '管理员密码不能小于6位字符',
    ];

}
